package com.example.musicwebcon.controller;

import com.example.musicwebcon.model.ResponseMessage;
import com.example.musicwebcon.model.dto.favlistDTO;
import com.example.musicwebcon.model.favlist;
import com.example.musicwebcon.service.serviceInterface.IfavlistService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/favlist")
public class favlistController {
    @Autowired
    IfavlistService favlistService;
    @PostMapping
    public ResponseMessage add(@Validated @RequestBody favlistDTO favlist){
        favlist songlist = favlistService.add(favlist);
        return ResponseMessage.success(songlist);
    }
    @GetMapping("/{songListId}")
    public ResponseMessage get(@PathVariable String songlistId){
        favlist songlist = favlistService.get(songlistId);
        return ResponseMessage.success(songlist);
    }
    @GetMapping
    public ResponseMessage getAll(){
        Iterable<favlist> songlists = favlistService.getALl();
        return ResponseMessage.success(songlists);
    }
    @GetMapping("/userall/{userId}")
    public ResponseMessage getAll(@PathVariable String userId){
        Iterable<favlist> songlists = favlistService.getALlByuserId(userId);
        return ResponseMessage.success(songlists);
    }
    @PutMapping
    public ResponseMessage edit(@Validated @RequestBody favlistDTO favlist){
        favlist songlist = favlistService.edit(favlist);
        return ResponseMessage.success(songlist);
    }
    @DeleteMapping("/{songListId}")
    public ResponseMessage delete(@PathVariable String songListId){
        favlistService.delete(songListId);
        return ResponseMessage.success(null);
    }
}
